@extends('admin/layout/master')
@section('title', '用户修改')
@section('title2', '用户修改')

@section('action')
  <a class="layui-btn layui-btn-small layui-btn-normal usersAdd_btn" href="{{ url('admin/user/index') }}"><i class="layui-icon"></i>用户列表</a>
	<!-- <a class="layui-btn layui-btn-small layui-btn-danger batchDel"><i class="layui-icon"></i>导出数据</a> -->
@endsection

@section('content')
<div class="error">
    @if (count($errors) > 0)
        <div class="alert alert-danger">
            错误列表：
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif
</div>

<form class="layui-form" name="mainform" action="{{ url('/admin/user/update', array('id'=>$olddata->id)) }}" method="post">
  <div class="layui-form-item">
    <label class="layui-form-label">头像</label>
    <div class="layui-input-block">
			<button type="button" class="layui-btn" id="test1">
				<i class="layui-icon">&#xe67c;</i>上传图片
			</button>
			<div style="float: left;width: 50px;height: 50px;margin-right: 20px;border: 1px solid #999;">
				<img style="width: 50px;height: 50px;" id="face" src="{{ !empty($olddata->face) ? $olddata->face : '/admin/images/face.jpg' }}" alt="">
			</div>
			<input type="hidden" name="face" value="">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">昵称</label>
    <div class="layui-input-block">
      <input type="text" name="nickname" placeholder="请输入昵称" value="{{ $olddata->nickname }}" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">用户名</label>
    <div class="layui-input-block">
      <input type="text" name="username" required  lay-verify="required" placeholder="请输入用户名" value="{{ $olddata->username }}" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">密码</label>
    <div class="layui-input-inline">
      <input type="text" name="password" placeholder="请输入密码" autocomplete="off" value="" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">辅助文字</div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      {{ csrf_field() }}
      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>

@endsection

@section('layuijs')
<script>
//一般直接写在一个js文件中
layui.use(['layer', 'form', 'upload'], function(){
var layer = layui.layer
,form = layui.form;
var upload = layui.upload;

	//执行实例
	var tag_token = $("[name='_token']").val();
  var uploadInst = upload.render({
    elem: '#test1' //绑定元素
		,data: {'_token':tag_token}
		,field: 'faceimg'
    ,url: "{{url('/admin/user/upload')}}" //上传接口
    ,done: function(res){
      //上传完毕回调
			if(res.state){
				console.log(res);
				layer.msg('上传成功');
				$("#face").attr("src",res.re);
				$("input[name='face']").val(res.re);
			} else {
				layer.msg('上传失败');
			}
    }
    ,error: function(){
      //请求异常回调
			layer.msg('上传失败');
    }
  });
});
</script>
@endsection